<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>书籍管理页</title>
<%@include file="includeHead.jsp"%>

</head>
<body>
	<table id="main_form" class="easyui-datagrid" title="书评列表"
		data-options="pagination:true,rownumbers:true,singleSelect:true,url:'${pageContext.request.contextPath}/GetBookReviewList',method:'get',toolbar:toolbarTop">
		<thead>
			<tr>
				<th data-options="field:'BookReviewsSimple',width:80">书评编号</th>
				<th data-options="field:'Book_ID',width:100">书籍编号</th>
				<th data-options="field:'us_id',width:100">书评作者编号</th>
				<th data-options="field:'BookReviewSimple_Title',width:80,align:'right'">书评标题</th>
				<th data-options="field:'BookReviewSimple_Date',width:80,align:'right'">书评发表时间</th>

			</tr>
		</thead>
	</table>

	<div id="addDiv" class="easyui-window" title="添加用户"
		data-options="iconCls:'icon-save',closed:true,modal:true,shadow:true,resizable:false"
		style="width: 400px; height: 300px; padding: 5px;">
		<div class="easyui-layout" data-options="fit:true">
			<div data-options="region:'center'" style="padding: 10px;">
				<form id="addForm" method="post">
					<table cellpadding="5">
						
						<!-- <tr id="tr_password">
							<td>书评编号:</td>
							<td><input id="form_BookReviewsSimple" name="BookReviewsSimple"
								data-options="required:true,validType:'minLength[5]'"></input></td>
						</tr> -->
						<tr>
							<td>书籍编号:</td>
							<td><input id="form_Book_ID" name="Book_ID"
								data-options="required:true"></input></td>
						</tr>
						<tr>
							<td>书评作者编号:</td>
							<td><input name="us_id" id="form_us_id"
								data-options="multiline:false"></input></td>
						</tr>
						<tr>
							<td>书评标题:</td>
							<td><input name="BookReviewSimple_Title" id="form_BookReviewSimple_Title"
								
								data-options="multiline:false,validType:'timeV'"></input></td>
						</tr>
						<tr>
							<td>书评发表时间:</td>
							<td><input name="BookReviewSimple_Date" id="form_BookReviewSimple_Date" class="easyui-datebox"
								data-options="multiline:true"></input></td>
						</tr>
												<tr>
							<td>书评内容:</td>
							<td><input name="BookReviewsDetial_Content" id="form_BookReviewsDetial_Content" 
								data-options="multiline:true"></input></td>
						</tr>
					</table>
				</form>
			</div>
			<div data-options="region:'south',border:false"
				style="text-align: right; padding: 5px 0 0;">
				<a class="easyui-linkbutton" data-options="iconCls:'icon-ok'"
					href="javascript:void(0)" onclick="" id="btn_Submit"
					style="width: 80px">确认</a> <a class="easyui-linkbutton"
					data-options="iconCls:'icon-cancel'" href="javascript:void(0)"
					onclick="$('#addDiv').window('close');" style="width: 80px">取消</a>
			</div>
		</div>
	</div>

	<script type="text/javascript">
	
	
	
		$.extend($.fn.validatebox.defaults.rules, {
			timeV : {
				validator : function(value) {
					var result = value
							.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/);
					if (result == null)
						return false;
					return true
				},
				message : '日期有误！请重新输入！.'
			},
			minLength : {
				validator : function(value, param) {
					return value.length >= param[0];
				},
				message : 'Please enter at least {0} characters.'
			}
		});
		/*日期控件本地化*/
		var options = {
	            required: "true",
	            missingMessage: "必填项",
	            formatter: function (date) {
	                var y = date.getFullYear();
	                var m = date.getMonth() + 1;
	                var d = date.getDate();
	                return y + "-" + (m < 10 ? ("0" + m) : m) + "-" + (d < 10 ? ("0" + d) : d);
	            }
	        }
		 $("#form_bookPubDate").datebox(options);
		 $("#form_bookAddDate").datebox(options);
		 
		var toolbarTop = [
				{
					text : '添加',
					iconCls : 'icon-add',
					handler : function() {
						$('#addDiv').form('clear');
						$("#addDiv").panel({
							title : "添加书籍"
						});
						var now = new Date();
						$('#form_BookReviewSimple_Date')
								.datebox(
										'setValue',
										now.getYear()
												+ "-"
												+ ((now.getMonth() + 1) < 10 ? "0"
														: "")
												+ (now.getMonth() + 1)
												+ "-"
												+ (now.getDate() < 10 ? "0"
														: "") + now.getDate());
						$('#btn_Submit').attr("onclick", " cmd('add');")
						$('#addDiv').window('open');
					}
				},
				{
					text : '修改',
					iconCls : 'icon-cut',
					handler : function() {
						$('#addDiv').form('clear');
						var row = $('#main_form').datagrid('getSelected');

						if (row != null) {
							//$("#form_BookReviewsSimple").val(row.BookReviewsSimple);
							$("#form_Book_ID").val(row.Book_ID);
							$("#form_us_id").val(row.us_id);

							$("#form_BookReviewSimple_Title").val(row.BookReviewSimple_Title);

							$("#form_BookReviewSimple_Date").datebox("setValue",row.BookReviewSimple_Date);
							$("#form_BookReviewsDetial_Content").val(row.BookReviewsDetial_Content);

							$("#addDiv").panel({
								title : "修改书评"
							});
							$('#btn_Submit').attr("onclick", "cmd('modify');")
							$('#addDiv').window('open');

						} else
							alert('请选择要修改的书评');

					}
				},
				'-',
				{
					text : '删除',
					iconCls : 'icon-save',
					handler : function() {
						var row = $('#main_form').datagrid('getSelected');
						if (row != null) {
							$
									.post(
											"${pageContext.request.contextPath }/AdminBookReviewControlServlet?control=delete&bookReviewid="
													+ row.BookReviewsSimple, null, function(
													result) {
												if (result != 'success') {
													alert(result);
												} else {
													alert("删除成功");
													closeForm();
													$('#main_form').datagrid(
															'reload');
												}
											}, "text");
						} else
							alert('请选择要删除的书籍');
					}
				} ];
		function cmd(c) {
			if ($("#addForm").form('enableValidation').form('validate')) {
				if (c == "add") {
					addFun();
				}
				if (c == "modify") {
					modifyFun();
				}
			}
		}
		function modifyFun() {
			var d = $("#addForm").serialize();
			d = d + "&BookReviewsSimple=" + $('#main_form').datagrid('getSelected').BookReviewsSimple;
			$
					.post(
							"${pageContext.request.contextPath }/AdminBookReviewControlServlet?control=modify",
							d, function(result) {
								if (result != 'success') {
									alert(result);
								} else {
									alert("修改成功");
									closeForm();
									$('#main_form').datagrid('reload');
									$('#addUserDiv').form('clear');
								}
							}, "text");
		}
		function addFun() {
			var d = $("#addForm").serialize();
			$
					.post(
							"${pageContext.request.contextPath }/AdminBookReviewControlServlet?control=add",
							d, function(result) {
								if (result != 'success') {
									alert(result);
								} else {
									alert("添加成功");

									closeForm();
									$('#main_form').datagrid('reload');
								}
							}, "text");
		}
		function closeForm() {
			$('#addDiv').window('close');
		}
	</script>

</body>
</html>